package com.doraemon.controller.user;

import com.doraemon.entity.Category;
import com.doraemon.result.Result;
import com.doraemon.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * c端分类管理Controller
 **/
@RestController("userCategoryController") // 设置自定义 Bean 名称，防止同名冲突
@RequestMapping("/user/category")
@Slf4j
@Api(tags = "分类相关接口")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /***
     * 根据类型查询分类
     * ---
     * @param type 分类类型 1为菜品分类，2为套餐分类
     * @return: com.doraemon.result.Result<java.util.List < com.doraemon.entity.Category>>
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type) {
        log.info("c端-根据类型查询分类：类型{}", type);

        // 调用Service层 getByType 方法，获取查询到的分类实体集合
        List<Category> categories = categoryService.getListByType(type);

        return Result.success(categories);
    }
}
